package com.woniu.bank.service.impl;

import com.github.pagehelper.PageHelper;
import com.woniu.bank.dto.ClientAndRatedDTO;
import com.woniu.bank.dto.RateFrozenDTO;
import com.woniu.bank.dto.RatedMainDTO;
import com.woniu.bank.dto.RatedUpdateDTO;
import com.woniu.bank.entity.Rated;
import com.woniu.bank.mapper.ClientInfoSheetMapper;
import com.woniu.bank.mapper.RatedMapper;
import com.woniu.bank.service.RatedService;
import com.woniu.bank.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author ：zhulongxing
 * @date ：Created in 2023/1/4 15:33
 * @description：
 * @modified By：
 * @version: $
 */
@Service
public class RatedServiceImpl implements RatedService {
    @Autowired
    private RatedMapper ratedMapper;

    @Autowired
    private ClientInfoSheetMapper clientInfoSheetMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return 0;
    }

    @Override
    public int insert(Rated record) {
        return 0;
    }

    @Override
    public int insertSelective(Rated record) {
        return ratedMapper.insertSelective(record);
    }

    @Override
    public Rated selectByPrimaryKey(Long id) {
        return null;
    }

    /**
     * lgy
     * echar图数据
     * @return
     */
    @Override
    public List<EcharVO> selectEc() {
        return ratedMapper.selectEc();
    }

    @Override
    public List<RatedUpdateVO> selectTwo(RatedUpdateDTO record) {
        PageHelper.startPage(record.getCurrentPage(),record.getPageSize());
        return ratedMapper.selectTwo(record);
    }

    @Transactional
    @Override
    public int updateClientAndRated(ClientAndRatedDTO clientAndRatedDTO) {
        clientInfoSheetMapper.updateClientAndRated(clientAndRatedDTO);
        ratedMapper.updateClientAndRated(clientAndRatedDTO);
        return 1;
    }

    @Override
    public List<ClientAndRatedVO> selectByid(Long ratedId) {
        return ratedMapper.selectByid(ratedId);
    }

    @Override
    public Rated selectByKey(Long id) {
        return ratedMapper.selectByKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Rated record) {
        return ratedMapper.updateByPrimaryKey(record);
    }

    @Override
    public int updateByPrimaryKey(Rated record) {
        return ratedMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<RatedMainVO> selectOne(RatedMainDTO record) {
        PageHelper.startPage(record.getCurrentPage(),record.getPageSize());
        return ratedMapper.selectOne(record);
    }

    @Override
    public List<RateFrozenVO> selectByFrozen(RateFrozenDTO frozenDTO) {
        PageHelper.startPage(frozenDTO.getCurrentPage(),frozenDTO.getPageSize());
        return ratedMapper.selectByFrozen(frozenDTO);
    }

    @Override
    public int updateRateFrozen(RateFrozenVO record) {
        Rated rated =new Rated();
        rated.setRatedId(record.getRatedId());
        if(record.getBak1().equals("冻结")){
            rated.setBak1("正常");
        }else if(record.getBak1().equals("正常")){
            rated.setBak1("冻结");
        }
        return ratedMapper.updateByPrimaryKeySelective(rated);
    }

}
